/*
 * Copyright (C) Michael Martin & Antonio Carrozzini (TBJD)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package org.tbjd.client.mediators;

import java.util.ArrayList;
import java.util.List;

import org.tbjd.client.interfaces.Decisionmaker;
import org.tbjd.client.interfaces.HasMediator;
import org.tbjd.client.interfaces.Observable;
import org.tbjd.client.interfaces.Observer;

public abstract class AbstractMediator implements Decisionmaker, Observable {

	private List<Observer> observers = new ArrayList<Observer>();

	/**
	 * This method adds an observer to the list of observers.
	 * Those observers will be notified and their update method called.
	 * An observer must implements <org.tbjd.client.interfaces.Observer> to be updated.
	 */
	public void addObserver(Observer o) {
		this.observers.add(o);
	}

	public void removeObserver(HasMediator o) {
		this.observers.remove(o);
	}

	public void notifyObservers(Object object) {
		for (Observer observer : observers) {
			observer.update(object);
		}
	}

}
